package com.mathassistant.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mathassistant.client.presenter.LoginPresenter.Display;

public class LoginView extends DialogBox implements Display{
	
	private TextBox usernameTextbox;
	private PasswordTextBox passwordTextbox;
	private Button loginButton;
	private Button closeButton;
	private Label warningLabel1;
	private Label warningLabel2;
	public LoginView() {
		createUI();
		showDialog();
	}
	
	private void createUI(){
		this.setText("Đăng nhập");
		VerticalPanel verticalPanel = new VerticalPanel();
		setWidget(verticalPanel);
		verticalPanel.setSize("100%", "100%");
		
		Label lblLogin = new Label("Nh\u1EADp th\u00F4ng tin t\u00E0i kho\u1EA3n :");
		lblLogin.setStyleName("dlgLogin-title");
		verticalPanel.add(lblLogin);
		
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setStyleName("dlgLogin-horizontal");
		verticalPanel.add(horizontalPanel);
		
		Label lblTnngNhp = new Label("T\u00EAn \u0111\u0103ng nh\u1EADp :");
		lblTnngNhp.setStyleName("dlgLogin-Label");
		horizontalPanel.add(lblTnngNhp);
		lblTnngNhp.setWidth("120px");
		
		usernameTextbox = new TextBox();
		horizontalPanel.add(usernameTextbox);
		usernameTextbox.setWidth("280px");
		
		HorizontalPanel horizontalPanel_1 = new HorizontalPanel();
		horizontalPanel_1.setStyleName("dlgLogin-horizontal");
		verticalPanel.add(horizontalPanel_1);
		
		Label lblMtKhu = new Label("M\u1EADt kh\u1EA9u :");
		lblMtKhu.setStyleName("dlgLogin-Label");
		horizontalPanel_1.add(lblMtKhu);
		lblMtKhu.setWidth("120px");
		
		passwordTextbox = new PasswordTextBox();
		horizontalPanel_1.add(passwordTextbox);
		passwordTextbox.setWidth("280px");
		
		HorizontalPanel horizontalPanel_3 = new HorizontalPanel();
		horizontalPanel_3.setStyleName("dlgLogin-horizontal");
		verticalPanel.add(horizontalPanel_3);
		horizontalPanel_3.setWidth("100%");
		
		VerticalPanel verticalPanel_1 = new VerticalPanel();
		horizontalPanel_3.add(verticalPanel_1);
		verticalPanel_1.setWidth("100%");
		
		warningLabel1 = new Label();
		verticalPanel_1.add(warningLabel1);
		warningLabel1.setWidth("");
		
		warningLabel1.addStyleName("dlgLogin-warning");
		
		warningLabel2 = new Label();
		verticalPanel_1.add(warningLabel2);
		warningLabel2.addStyleName("dlgLogin-warning");
		
		HorizontalPanel horizontalPanel_2 = new HorizontalPanel();
		horizontalPanel_2.setStyleName("dlgLogin-horizontal");
		verticalPanel.add(horizontalPanel_2);
		
		loginButton = new Button("\u0110\u0103ng nh\u1EADp");
		loginButton.addStyleName("dlgLogin-button");
		horizontalPanel_2.add(loginButton);
		loginButton.setWidth("110px");
		
		Label label = new Label("");
		label.setStyleName("dlgLogin-Label");
		horizontalPanel_2.add(label);
		
		closeButton = new Button("Tho\u00E1t");
		closeButton.addStyleName("dlgLogin-button");
		horizontalPanel_2.add(closeButton);
		closeButton.setWidth("110px");
		
	}

	@Override
	public HasClickHandlers getLoginButton() {
		// TODO Auto-generated method stub
		return loginButton;
	}

	@Override
	public HasClickHandlers getCancelButton() {
		// TODO Auto-generated method stub
		return closeButton;
	}

	@Override
	public HasValue<String> getUsernameTextbox() {
		// TODO Auto-generated method stub
		return usernameTextbox;
	}

	@Override
	public HasValue<String> getPasswordTextbox() {
		// TODO Auto-generated method stub
		return passwordTextbox;
	}
	
	@Override
	public Widget asWidget() {
		// TODO Auto-generated method stub
		return this;
	}
	
	@Override
	public void hideDialog() {
		// TODO Auto-generated method stub
		this.hide(true);
	}
	
	@Override
	public void showDialog() {
		// TODO Auto-generated method stub
		this.setAnimationEnabled(true);
		this.setGlassEnabled(true);
		this.center();
		usernameTextbox.setFocus(true);
		this.show();
	}
	
	@Override
	public void setWarning(String line1, String line2) {
		// TODO Auto-generated method stub
		warningLabel1.setText(line1);
		warningLabel2.setText(line2);
	}
}
